/**
 * Created by wengms on 2016/11/20.
 */
define([angular], function () {
    return function($scope,GillionMsg,Resource,$dataSourceManager,$http){
        $scope.package={};
        $scope.removeShow=false;
        var holidaysRes = Resource("/grule-manager/holidays/:id",{
            "id":"@id"
        });
        $scope.actions = {
            deletePackage:function(id){
                GillionMsg.confirm('提示信息', '是否确定删除？',
                    function (r) {
                        if (r) {
                            holidaysRes.delete({"id":id},function(response){
                                if (response.success){
                                    GillionMsg.alert("提示", "删除成功");
                                    $scope.actions.refreshTable();
                                }else{
                                    GillionMsg.alert("提示","删除失败");
                                    $scope.actions.refreshTable();
                                }
                            });
                        }
                    })
            },
            openEditView:function(dataDict){
                var title = !dataDict?"新建":"编辑";
                GillionMsg.showUrl({
                    title:title,
                    data:dataDict,
                    url: '/html2/system/holidays/holidays-detail',
                    width:400,
                    height:360,
                    onClose:function(data){
                        //刷新表格内容
                        $scope.actions.refreshTable();
                    }
                });
            },
            search:function(){
                var params={};
                params.holiday =$scope.holiday;
                $dataSourceManager.dataSources['holidaysSource'].params=params;
                $dataSourceManager.dataSources['holidaysSource'].doRequestData();
            },
            publish:function(){
                $http.get('/grule-manager/holidays/publish').success(function (data) {
                if(data.reload==true){
                        console.log("-------------");
                    }else {
                        console.log("=============");
                    }
                });
            },
            refreshTable:function(){
                $dataSourceManager.dataSources['holidaysSource'].doRequestData();
            },
        }
        $scope.myKeyup = function(e){
            var keycode = window.event?e.keyCode:e.which;
            if(keycode==13){
                $scope.actions.search();
            }
        };
        $scope.$watch('package.name',function(newValue,oldValue){
            if(newValue==""){
                $scope.removeShow=false;
                $scope.actions.search();
            }else if(newValue){
                $scope.removeShow=true;
            }
        });
        $scope.deleteInput=function(){
            $scope.package={name:""};
        }
    };
});